<template>
	<view class="container">
		<!-- <navbar title="邀请好友" background="transparent"></navbar> -->
		<view class="bg">
			<image :src='background' mode="aspectFill" show-menu-by-longpress="true"></image>
		</view>
		<view class="wrap">
			<view class="btn" @click="download()">
				保存图片
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				background: '',
			};
		},
		onLoad() {
			console.log('background',this.background)
			this.getInvite_code()
		},
		methods:{
			/* 获取分享码 */
			getInvite_code(){
				let that = this;
				app.globalRequest({
					api: app.getApi().user.inviteCode,
					method:'post',
				}).then(res => {
					console.log('res', res)
					if (res.code == 1) {
						that.background = res.qrcode
					}
				}).catch(err => {
				
				})
			},
			
			// 下载图片
			download(){
				uni.downloadFile({
				  url: this.background,
				  success: (res) => {
					uni.saveImageToPhotosAlbum({
						//图片路径，不支持网络图片路径
						filePath: res.tempFilePath,
						success: (res) => {
							uni.hideLoading();
							setTimeout(()=>{
								return uni.showToast({
									title: "保存成功"
								});
							},1500)
							
						},
						fail: (res) => {
					
						},
						complete: (res) => {uni.hideLoading();},
					})
				
				  }
				
				});
			},
		}
	}
</script>
<style>
	page {
		height:100%;
	}
</style>
<style lang="scss" scoped>
	.container{
		width:100%;
		height: 100%;
	}
	image{
		width: 100%;
		height:100%;
	}
	.bg{
		width: 100%;
		height:100%;
		position: fixed;
		left:0;
		top:0;
	}
	.wrap{
		position: fixed;
		z-index:222;
		bottom: 200rpx;
		width: 100%;
	}
	.title{
		text-align: center;
		padding-top:264rpx;
		font-size: 36rpx;
	}
	.code{
		width: 416rpx;
		height: 416rpx;
		background: #ccc;
		margin:112rpx auto 0;
	}
	
	.btn{
		width: 90%;
		background-color: #000000;
		line-height: 94rpx;
		height: 94rpx;
		text-align: center;
		color: #fff;
		font-size: 32rpx;
		margin: auto;
	}
</style>
